// 定义处理的方法(方便扩展)

import { isObject } from './utils.js';
import { createReactive } from './reactive.js'

const get = createGetter();
const set = createSetter();

function createGetter() {
  return function (target, key, receiver) {
    const res = Reflect.get(target, key, receiver);

    if (isObject(res)) { // 如果返回的值也是对象则递归
      return createReactive(res);
    }

    return res;
  }
}

function createSetter() {
  return function (target, key, value, receiver) {
    return Reflect.set(target, key, value, receiver);
  }
}

export const proxyHandler = {
  get,
  set
}